package Aspect;

import bean.Student;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author HLF
 * @version V1.0
 * @package Aspect
 * @date 2021/10/27 17:11
 */

@Aspect
@Component(value = "aspect01")
public class Aspect01 {

    @Around(value = "execution(* *..impl.StudentServiceImpl.registStudent(..))")
    public Object myAround(ProceedingJoinPoint pjp) {
        //获取目标方法的参数
        Object[] args = pjp.getArgs();
        Student arg = (Student) args[0];
        System.out.println(arg.getName());
        Object res = null;
        try {
            //在目标方法之前执行业务方法，输出日志功能
            String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
            System.out.println("日志：" + time);
            res = pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return res;
    }
}
